﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enter.Entity;
using Enter.BizLogic;

namespace Enter.Services.Mail
{
    public partial class Mail : IMail
    {
        #region 用户登录

        public bool ValidateUser(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("值不能为空。", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("值不能为空。", "password");

            return true;
        }
        //public bool ValidateUser(string UserName, string Password,string ConfirmPassword)
     
        //}

        public T201_UserEntity UserRegister(T201_UserEntity entity)
        {

            try
            {
               
                T201_UserBLLSub bll = new T201_UserBLLSub();
                int id = bll.Insert(entity);
                if (id > 0)
                {
                    entity.UIID = id;
                    T202_UserInfoBLLSub userbll = new T202_UserInfoBLLSub();
                    T202_UserInfoEntity user = new T202_UserInfoEntity();
                    user.UID = id;
                    user.ULastLoginTime = DateTime.Now;
                    user.URegTime = DateTime.Now;
                    userbll.Insert(user);
                    return entity;
                }
                return null;
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        public bool UpdatePwd(string uID, string uPwd)
        {
            T201_UserBLLSub bll = new T201_UserBLLSub();
            return bll.UpdatePwd(uID, uPwd);
        }
        /// <summary>
        /// 根据用户名获取用户信息
        /// </summary>
        /// <param name="uName"></param>
        /// <param name="uPWD"></param>
        /// <returns></returns>
        public T201_UserEntity GetUserByName(string uName)
        {
            T201_UserBLLSub bll = new T201_UserBLLSub();
            return bll.GetObjectByName(uName);
        }
        /// <summary>
        /// 根据用户ID获取用户信息
        /// </summary>
        /// <param name="uName"></param>
        /// <param name="uPWD"></param>
        /// <returns></returns>
        public T201_UserEntity GetUserByID(int uID)
        {
            T201_UserBLLSub bll = new T201_UserBLLSub();
           return bll.GetObjectByUIID(uID);
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="uName"></param>
        /// <param name="uPWD"></param>
        /// <returns></returns>
        public T201_UserEntity UserLogin(string uName, string uPWD)
        {
            T201_UserBLLSub bll = new T201_UserBLLSub();

            return bll.UserLogin(uName, uPWD);
        }
        /// <summary>
        /// 检查用户名是否可用
        /// </summary>
        /// <param name="userName"></param>
        /// <returns>T 可用 F 不可用</returns>
        public bool CheckUserName(string userName)
        {
            T201_UserBLLSub bll = new T201_UserBLLSub();
            return bll.CheckUserName(userName);

        }
        /// <summary>
        /// 检查用户名是否可用
        /// </summary>
        /// <param name="userName"></param>
        /// <returns>T 可用 F 不可用</returns>
        public bool CheckUserPhone(string userPhone)
        {
            T201_UserBLLSub bll = new T201_UserBLLSub();
            return bll.CheckUserPhone(userPhone);
        }
        #endregion

        #region 用户基本信息
        public bool UpdateUserInfo(T202_UserInfoEntity entity)
        {
            T202_UserInfoBLLSub bll = new T202_UserInfoBLLSub();
            return bll.Update(entity);
        }
        public T202_UserInfoEntity GetUserInfo(int uID)
        {
            T202_UserInfoBLLSub bll = new T202_UserInfoBLLSub();
            return bll.GetObjectByUID(uID);
        }
        /// <summary>
        /// 修改用户头像
        /// </summary>
        /// <returns></returns>
        public int UpdateUserHead(T202_UserInfoEntity model)
        {
            T202_UserInfoBLLSub bll = new T202_UserInfoBLLSub();
            return bll.UpdateUserHead(model);
        }
        #endregion

        #region 用户收货地址
        /// <summary>
        /// 保存收货地址
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool SaveUserAddress(T203_UserAddressEntity entity)
        {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
           return bll.Save(entity);
        }
      
        /// <summary>
        /// 删除收货地址
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DelUserAddress(int id,int uID)
        {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
            return bll.DelUserAddress(id, uID);
        }
        /// <summary>
        /// 获取地址内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T203_UserAddressEntity GetAddressInfo(int id)
        {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
            return bll.GetObjectByAID(id);
        }
        /// <summary>
        /// 取消默认地址
        /// </summary>
        /// <returns></returns>
        public bool CancelDefalutAdd(int ID)
        {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
            return bll.CancelDefalutAdd(ID);
        }
        /// <summary>
        /// 取消默认地址
        /// </summary>
        /// <param name="uID"></param>
        /// <returns></returns>
        public bool CancelDefalutAddbyUID(int uID) {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
            return bll.CancelDefalutAddbyUID(uID);
        }

        /// <summary>
        /// 设置为默认地址
        /// </summary>
        /// <returns></returns>
        public bool SetDefalutAdd(int ID,int uID)
        {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
            return bll.SetDefalutAdd(ID, uID);
        }
        /// <summary>
        /// 获取用户收货地址
        /// </summary>
        /// <param name="uID"></param>
        /// <returns></returns>
        public List<T203_UserAddressEntity> GetUserAdd(int uID)
        {
            T203_UserAddressBLLSub bll = new T203_UserAddressBLLSub();
            return bll.GetUserAdd(uID);
        }
        #endregion

        #region 商品收藏
        public bool AddGoodCollect(int uID,string shopNO,string gNo)
        {
            T212_UserGoodCollectionEntity Entity=new T212_UserGoodCollectionEntity();
            Entity.UIID = uID;
            Entity.ShopNo = shopNO;
            Entity.GoodNo = gNo;
            T212_UserGoodCollectionBLLSub bll = new T212_UserGoodCollectionBLLSub();
           return bll.Save(Entity);
        }
          /// <summary>
        /// 获取用户收藏
        /// </summary>
        /// <param name="uID"></param>
        /// <returns></returns>
        public List<T212_UserGoodCollectionEntity> GetUserGoodColl(int uID, int pageSize, int currentPageIndex, out int totalPages, out int totalCount)
        {
            T212_UserGoodCollectionBLLSub bll = new T212_UserGoodCollectionBLLSub();
            return bll.GetUserGoodColl(uID, pageSize, currentPageIndex, out totalPages, out totalCount);
        }
        #endregion

        #region 店铺收藏
        public bool AddShopCollect(int uID, int shopID)
        {
            T211_UserShopCollectionEntity Entity = new T211_UserShopCollectionEntity();
            Entity.UIID = uID;
            Entity.ShopID = shopID;
            
            Entity.CAddTime = DateTime.Now;
            T211_UserShopCollectionBLLSub bll = new T211_UserShopCollectionBLLSub();
            return bll.Save(Entity);
        }
        /// <summary>
        /// 获取用户收藏
        /// </summary>
        /// <param name="uID"></param>
        /// <returns></returns>
        public List<T211_UserShopCollectionEntity> GetUserShopColl(int uID, int pageSize, int currentPageIndex, out int totalPages, out int totalCount)
        {
            T211_UserShopCollectionBLLSub bll = new T211_UserShopCollectionBLLSub();
            return bll.GetUserShopColl(uID, pageSize, currentPageIndex, out totalPages, out totalCount);
        }
        #endregion

        #region 商品评论
        /// <summary>
        /// 商品评论
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool AddGoodComment(T205_UserGoodCommentEntity entity)
        {
            T205_UserGoodCommentBLLSub bll = new T205_UserGoodCommentBLLSub();
            return bll.Save(entity);
        }
        /// <summary>
        /// 买家对店铺的评论
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool AddTreadComment(T206_UserTradeCommentEntity entity)
        {
            T206_UserTradeCommentBLLSub bll = new T206_UserTradeCommentBLLSub();
            return bll.Save(entity);
        }
        /// <summary>
        /// 店铺对买家的评论
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool AddShopComment(T404_ShopTradeCommentEntity entity)
        {
            T404_ShopTradeCommentBLLSub bll = new T404_ShopTradeCommentBLLSub();
            return bll.Save(entity);
        }
        /// <summary>
        /// 根据订单获取评论
        /// </summary>
        /// <param name="OrderID"></param>
        /// <returns></returns>
        public T205_UserGoodCommentEntity GetObjectByOrderID(int OrderID, int GID)
        {
            T205_UserGoodCommentBLLSub bll = new T205_UserGoodCommentBLLSub();
           return bll.GetObjectByOrderID(OrderID, GID);
        }

        /// <summary>
        /// 用户评论
        /// </summary>
        /// <param name="uID"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public List<T205_UserGoodCommentEntity> GetUserCommnet(int uID, int pageSize, int currentPageIndex, out int totalPages, out int totalCount)
        {

            T205_UserGoodCommentBLLSub bll = new T205_UserGoodCommentBLLSub();
            return bll.GetGoodCommnet(uID, pageSize, currentPageIndex, out totalPages, out totalCount);
        }
        /// <summary>
        /// 某件商品的评论
        /// </summary>
        /// <param name="gID"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public List<T205_UserGoodCommentEntity> GetGoodCommnet(int gID, int pageSize, int currentPageIndex, out int totalPages, out int totalCount)
        {
            T205_UserGoodCommentBLLSub bll = new T205_UserGoodCommentBLLSub();
            return bll.GetGoodCommnet(gID, pageSize, currentPageIndex, out totalPages,out totalCount);
        }

        // <summary>
         /// 店铺对买家的评论
         /// </summary>
         /// <param name="uID"></param>
         /// <param name="entity"></param>
         /// <returns></returns>
        public IList<T404_ShopTradeCommentEntity> GetCommnetByUser(int uID, int pageSize, int currentPageIndex, out int totalPages, out int totalCount)
         {
           T404_ShopTradeCommentBLLSub bll=new T404_ShopTradeCommentBLLSub();
           return bll.GetCommnetByUser(uID, pageSize, currentPageIndex, out totalPages, out totalCount);
            
            
         }
         /// <summary>
         /// 店铺对买家的评论
         /// </summary>
         /// <param name="gID"></param>
         /// <param name="entity"></param>
         /// <returns></returns>
        public IList<T404_ShopTradeCommentEntity> GetCommnetByShop(int shopID, int pageSize, int currentPageIndex, out int totalPages, out int totalCount)
        {
            T404_ShopTradeCommentBLLSub bll = new T404_ShopTradeCommentBLLSub();
            return bll.GetCommnetByShop(shopID, pageSize, currentPageIndex, out totalPages, out totalCount);

        }
        #endregion
    }
}
